package com.itlaobing.dispatch.redirect;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet( "/search/*" )
public class SearchServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request , HttpServletResponse response )
            throws ServletException, IOException {
        this.log("老夫不搞搜索，你去找百度去");

        String url = "http://www.baidu.com/s?wd=matebook" ;

        // 以下操作完成了 response.setStatus( 302 )  和 response.setHeader( "location" , url )
        response.sendRedirect( url ); // 重定向(redirect)后的地址(location)可以是同一个服务器内部的，也可以是服务器外部的

    }
}
